package interview.juc;

import lombok.val;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @Author: zhangrongqing
 * @Date: 2019/12/9 15:24
 */
//查看可重入性
public class ReentranLockDemo {
    public static void main(String[] args) {
        ReentranLockDemo reentranLockDemo = new ReentranLockDemo();
        new Thread(new Runnable() {
            @Override
            public void run() {
                reentranLockDemo.test();
            }
        }).start();
    }

    public void test() {
        ReentrantLock lock = new ReentrantLock();
        try {
            lock.lock();
            System.out.println("123");
            lock.lock();                  //可以重复上锁
            System.out.println("我是可重入的");
        } finally {
            lock.unlock();
        }
    }
}
